<?php
/**
 * ReportController
 *-------------------------
 *
 * Deal with menu display, selected status. Top menu - sub menu
 *
 * PHP versions 5
 *
 * LICENSE: This source file is from Smarter Ver4.0, which is a comprehensive shopping engine
 * that helps consumers to make smarter buying decisions online. We empower consumers to compare
 * the attributes of over one million products in the computer and consumer electronics categories
 * and to read user product reviews in order to make informed purchase decisions. Consumers can then
 * research the latest promotional and pricing information on products listed at a wide selection of
 * online merchants, and read user reviews on those merchants.
 * The copyrights is reserved by http://www.mezimedia.com.
 * Copyright (c) 2005, Mezimedia. All rights reserved.
 *
 * @author     Steven.Ying <steven_ying@mezimedia.com>
 * @copyright  (C) 2004-2008 Mezimedia.com
 * @license    http://www.mezimedia.com  PHP License 5.2
 * @version    CVS: $Id: ReportController.php
 * @link       http://pms.mezimedia.com/
 * @deprecated File deprecated in Release 1.0
 */

require_once 'Zend/Session/Namespace.php';
//require_once('app/model/Task.php');

class ReportController extends Zend_Controller_Action{
	function preDispatch(){
	    $this->view->user = Zend_Auth :: getInstance()->getIdentity();
		$this->view->controller = $this->_request->getControllerName();
		$this->view->action = $this->_request->getActionName();
		$subMenu = array (
			'Task Report' => array (
				'key' => 'index',
				'url' => '/report/',
				'selected' => false,
				'title' => 'Page to list user todo, msg ...',
            ),
			'User Report' => array (
				'key' => 'profile',
				'url' => '/report/users',
				'selected' => false,
				'title' => 'Page to list user todo, msg ...'
			),
			'Resource Report' => array (
				'key' => 'engineerwe',
				'url' => '/report/engineerwe',
				'selected' => false,
				'title' => 'Page to list user todo by group, msg ...'
			),
			'Calendar Report' => array (
				'key' => 'calendar',
				'url' => '/report/calendar',
				'selected' => false,
				'title' => 'Page to list task for calendar, msg ...'
			)
		);
		$menu = new Menu();
		$menuTree = $menu->renderMenu($this->_request->getControllerName(), $this->_request->getActionName(), $subMenu);
		$this->view->menuTree = $menuTree;
		$this->view->metaTitle = "Reports - Task Tracking System V1.0";
	}

	public function indexAction(){
	}

	public function noRouteAction(){
        $this->_redirect('/');
    }

    public function tasksAction(){

    }

    public function usersAction(){
    }

	public function calendarAction(){
		$engineer = $this->_getParam('resourceid');
		if($engineer <1){
			$engineer = 170;
		}
		Zend_Loader :: loadClass('User');
		$oUser = new User();
		$this->view->resourceList = $oUser->findUser("tt_team_id=1");
		$this->view->curResourceId = $engineer;

		Zend_Loader :: loadClass('Calendar');
		$oCalendar = new Calendar($engineer, $this->_getParam('year'), $this->_getParam('month'));
		$this->view->taskCalendar = $oCalendar->getHtmlData();
	}

    public function engineerweAction(){
		Zend_Loader :: loadClass('User');
		$oUser = new User();
		$this->view->engineerList = $oUser->findUser("tt_team_id=1");

		Zend_Loader :: loadClass('Task');
		$oTask = new Task();
		$this->view->statusList = $oTask->getEntities("status");
		unset($this->view->statusList[0]);
		$this->view->propertyList = $oTask->getEntities("property");
		unset($this->view->propertyList[0]);
    }

	public function rptdataeweAction(){
    	$this->view->rptType = $this->_getParam('rpt');
    	Zend_Loader :: loadClass('Task');
		$oTask = new Task();

		$dimensions = array(
			'engineer'=>array('orderby'=>'developer_id', 'showname'=>'Resource'),
			'property'=>array('orderby'=>'property_id', 'showname'=>'Property'),
			'pm'=>array('orderby'=>'manager_id', 'showname'=>'PM'),
			'status'=>array('orderby'=>'task_status', 'showname'=>'Status'),
		);
		//collect task filter params
		if($this->_getParam('dates')!=""){
			$params['startDate'] = $this->_getParam('dates');
		}else{
			$params['startDate'] = date("Y-m-d");
		}
		if($this->_getParam('datee')!=""){
			$params['endDate'] = $this->_getParam('datee');
		}else{
			$params['endDate'] = date("Y-m-d");
		}
    	if($this->_getParam('engineers')!=""){
			$params['engineers'] = $this->_getParam('engineers');
		}
		if($this->_getParam('statuss')!=""){
			$params['statuss'] = $this->_getParam('statuss');
		} else {
			$params['notinstatus'] = '2,9';
		}
		if($this->_getParam('propertys')!=""){
			$params['propertys'] = $this->_getParam('propertys');
		}
		if($this->_getParam('dimension')!="" && isset($dimensions[$this->_getParam('dimension')])){
			$params['orderby'] = $dimensions[$this->_getParam('dimension')]['orderby'];
			$this->view->dimension = $dimensions[$this->_getParam('dimension')]['showname'];
		}

		$taskList = $oTask->getFilteredTasksByRpt($params);
		$this->view->taskList = $taskList;
		$this->view->show=$this->_getParam('show');
    }

	public function rptdataAction(){
	  $this->view->rptType = $this->_getParam('rpt');

		if($this->_getParam('rpt')=='tskscd'){
			Zend_Loader :: loadClass('Task');
			$oTask = new Task();

			//collect task filter params
			if($this->_getParam('dates')!=""){
				$params['startDate'] = $this->_getParam('dates');
			}else{
				$params['startDate'] = date("Y-m-d");
			}
			if($this->_getParam('datee')!=""){
				$params['endDate'] = $this->_getParam('datee');
			}else{
				$params['endDate'] = date("Y-m-d");
			}
			$taskList = $oTask->getFilteredTasks($params);
			$this->view->taskList = $taskList;
			$this->view->show=$this->_getParam('show');
		}

		elseif($this->_getParam('rpt')=='userscd'){

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			Zend_Loader :: loadClass('Task');
			$oTask = new Task();

			//collect task filter params
			$util = new Utils();

			if($this->_getParam('show')=='list'){

					if($this->_getParam('dates')!=""){
						 $dataRange=$util->getDataRange($this->_getParam('dates'));

						 $params['startDate'] = $dataRange[0];
						 $params['endDate'] = $dataRange[1];

					}else{
						 $dataRange=$util->getDataRange(date("Y-m-d"));
						 $params['startDate'] = $dataRange[0];
						 $params['endDate'] = $dataRange[1];
					}


					$taskList = $oTask->getUserTasksList($params);
					//loop task to fetch a unique user list

					$this->view->taskList = $taskList;
					$this->view->show=$this->_getParam('show');


			}else{

					if($this->_getParam('dates')!=""){
						 $dataRange=$util->getDataRange($this->_getParam('dates'));

						 $params['startDate'] = $dataRange[0];
						 $params['endDate'] = $dataRange[1];

					}else{
						 $dataRange=$util->getDataRange(date("Y-m-d"));
						 $params['startDate'] = $dataRange[0];
						 $params['endDate'] = $dataRange[1];
					}

					$topTaskList = $oTask->getTopTasks($params);

					$taskList = $oTask->getUserTasksCart($params);

					//loop task to fetch a unique user list

					$taskUserList = array();
					foreach($taskList as $task){
						if(!isset($taskUserList[$task['name']])){
							$taskUserList[$task['name']] = $task['id'];
						}

					}

					$this->view->taskUserList = $taskUserList;
					$this->view->topTaskList = $topTaskList;
					$this->view->taskList = $taskList;

			}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		}

	}

	public function rptsettingsAction(){
		$this->view->rptType = $this->_getParam('rpt');
	}

	/*Test the report format*/
	public function testAction(){

	}
}